using System;
using UnityEngine;

namespace AssemblyCSharp
{
	public class FlagCheckpointStateDisabling : IFSMState
	{
		private GameObject m_go_Flag;
		
		private const float m_DisablingDuration = 2;
		
		private const float m_DisabledHeight = 20;
		
		private float m_ScaledDisabledHeight;
		
		private float m_StartTimeDisabling;
		
		private float m_StartHeight;
		
		public FlagCheckpointStateDisabling (FSMRunner Runner, GameObject obj)
		{
			_Runner = Runner;
			_GameObject = obj;
			_State = (int)FlagCheckpointState.eDisabling;
			m_go_Flag = _GameObject.transform.Find("flag_flag").gameObject;
			m_ScaledDisabledHeight = m_DisabledHeight;//_GameObject.transform.lossyScale.y * m_DisabledHeight;
		}
		
		public override void OnEnter ()
		{
			m_StartTimeDisabling = Time.time;
			m_StartHeight = m_go_Flag.transform.localPosition.y;
			base.OnEnter ();
		}
		
		public override void OnExecute ()
		{
			float TimeParameter = (Time.time - m_StartTimeDisabling) / m_DisablingDuration;
			float NewHeight = Mathf.Lerp(m_StartHeight, m_ScaledDisabledHeight, TimeParameter);
			
			Vector3 CurrentPosition = m_go_Flag.transform.localPosition;
			CurrentPosition.y = NewHeight;
			m_go_Flag.transform.localPosition = CurrentPosition;
			
			if(TimeParameter >= 1)
			{
				_Runner.SetCurrentState((int)FlagCheckpointState.eDisabled);
			}
			
			base.OnExecute ();
		}
	}
}

